package com.chen.servicedriveruser.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chen.internalcommon.constant.CommonStatusEnum;
import com.chen.internalcommon.dto.DriverUserWorkStatus;
import com.chen.internalcommon.dto.ResponseResult;
import com.chen.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenLiuPing
 **/
@Service
@Slf4j
public class DriverUserWorkStatusService {
    @Autowired
    private DriverUserWorkStatusMapper driverUserWorkStatusMapper;

    public ResponseResult changeWorkStatus(Long driverId, Integer workStatus) {
        LambdaUpdateWrapper<DriverUserWorkStatus> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(DriverUserWorkStatus::getDriverId, driverId)
                .set(workStatus != null, DriverUserWorkStatus::getWorkStatus, workStatus);
        int update = driverUserWorkStatusMapper.update(null, updateWrapper);
        if (update == 0) {
            log.info("司机{}不存在,状态修改失败", driverId);
            return ResponseResult.fail(CommonStatusEnum.DRIVER_NOT_EXISTS);
        }
        log.info("司机{}状态修改成功",driverId);
        return ResponseResult.success();
    }
}
